//
//  SceneDelegate.swift
//  WeiBoDemo
//
//  Created by China Dragon on 2023/8/22.
//

import UIKit

/*
 https://blog.csdn.net/qq_31598345/article/details/119979791
 新版的iOS项目中，AppDelegate仅仅用来承担APP生命周期事件，UiWindow的持有交给了SceneDelegate。
 在拥有stroryboard的时候，会默认的初始化sceneDelegate中的UiWindow，删除后，需要我们自己手动添加。
 
 
 Could not find a storyboard named 'Main' in bundle NSBundle
 https://blog.51cto.com/u_15955464/6058472
 */
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
      
//        guard let _ = (scene as? UIWindowScene) else { return } // 创建默认的
        guard let scene = (scene as? UIWindowScene) else { return }
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
//        self.window?.windowScene = (scene as? UIWindowScene)
        self.window?.windowScene = scene
        self.window?.backgroundColor = UIColor.white
//        self.window?.backgroundColor = UIColor(patternImage: UIImage(named: "LaunchScreen")!)
        self.window?.rootViewController = MainViewController()
        self.window?.makeKeyAndVisible()
       
    }

    func sceneDidDisconnect(_ scene: UIScene) {
        // Called as the scene is being released by the system.
        // This occurs shortly after the scene enters the background, or when its session is discarded.
        // Release any resources associated with this scene that can be re-created the next time the scene connects.
        // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
        // Called when the scene has moved from an inactive state to an active state.
        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
    }

    func sceneWillResignActive(_ scene: UIScene) {
        // Called when the scene will move from an active state to an inactive state.
        // This may occur due to temporary interruptions (ex. an incoming phone call).
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
        // Called as the scene transitions from the background to the foreground.
        // Use this method to undo the changes made on entering the background.
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
        // Called as the scene transitions from the foreground to the background.
        // Use this method to save data, release shared resources, and store enough scene-specific state information
        // to restore the scene back to its current state.
    }


}

